%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% 09.22.23. Device 1 data (Half-Wave Dipolar Metal-Semiconductor Laser, Fig. 3b)
%%% Sangyeon (Fred) Cho, fredericksy.cho@gmail.com
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear all
lambda=open('lambda_device2.mat').lambda;
spectrum=open('spectrum_device2.mat').spectrum;
pump=open('pump_device2.mat').pump;
x0=300;
y0=300;
width=200*0.8;
height=300*0.8;
n = input('Enter a number: ');
switch n
    case 1 %Graph 2D
for i=1:20
figure(1)
plot(lambda,spectrum(i,:))
xlim([1050 1650])
xlabel('Wavelength (nm)')
ylabel('Ouptut (Photons)')
set(gcf,'position',[x0,y0,width,height])
set(gca,'TickDir','out'); 
hold on



end
    
case 2 %Smoothing 
for i=1:20
spectrum_s(i,:)=smooth(spectrum(i,:),'rlowess',100);
figure(1)
plot(lambda,spectrum_s)
xlim([1050 1650])
xlabel('Wavelength (nm)')
ylabel('Ouptut (Photons)')
set(gcf,'position',[x0,y0,width,height])
set(gca,'TickDir','out'); 
hold on
end

[X, Y] = meshgrid( pump,lambda);
figure (2)
plot3(X, Y, spectrum_s);
ylim([1100 1600])
set (gca,'Ydir','reverse')
set(gca, 'colormap', jet)
set(gca,'TickDir','out'); 
ylabel('Wavelength (nm)')
zlabel('Ouptut (Photons)')
xlabel('Pump(mJ/cm2)')

case 3 %Input-Output

for i=1:20
m=spectrum(i,:)-spectrum(3,:).*mean(spectrum(i,1200:1500))./mean(spectrum(3,1200:1500));
mode(i,:)=m;
figure(1)
plot(lambda, mode(i,:))
xlim([1050 1650])
xlabel('Wavelength (nm)')
ylabel('Ouptut (Photons)')
set(gcf,'position',[x0,y0,width,height])
set(gca,'TickDir','out'); 
hold on
out(i)=sum(mode(i,850:1150),2);
end
figure(2)
plot(pump.*10^3, out,'o')
xlabel('Pump (mJ/cm2)')
ylabel('Ouptut (Photons)')
2
    case 4  %Linewidth
for i=1:20
m=spectrum(i,:)-spectrum(3,:).*mean(spectrum(i,1200:1500))./mean(spectrum(3,1200:1500));
mode(i,:)=m;
end
for i=1:20
F=fit(lambda(850:1150).',squeeze(mode(i,850:1150)).','gauss1');
fwhm(i)=F.c1.*sqrt(2.*log(2));
end
figure(1)
plot(pump(6:20).*10^3, fwhm(6:20),'o')
xlabel('Pump (mJ/cm2)')
ylabel('Linewidth (nm)')
end

